// @Author EthanScriptOn
// @Desc
package log_worker_factory

import (
	"gitee.com/fatzeng/srf_switch_basic_components/pool"
	"gitee.com/fatzeng/srf_switch_log/log_define"
	"gitee.com/fatzeng/srf_switch_log/log_dispatcher"
	"gitee.com/fatzeng/srf_switch_log/log_queue"
	"gitee.com/fatzeng/srf_switch_log/log_worker"
)

type LoggerCollectWorkerFactory struct {
}

func GenerateLoggerCollectWorkerFactory() *LoggerCollectWorkerFactory {
	return new(LoggerCollectWorkerFactory)
}

func (l *LoggerCollectWorkerFactory) Create() (pool.Worker, error) {
	collectWorker := log_worker.GenerateLoggerCollectWorker(log_queue.GenerateLogQueue(), 1)
	// Add a precursor to a submission
	if err := collectWorker.DefaultWorker.SetSubmitBeforeOption(collectWorker.FilterOption); err != nil {
		return nil, err
	}
	// Get the data coordinator and register the current queue
	if dataDispatcher, err := log_dispatcher.GetDataDispatcherInstance(); err != nil {
		return nil, err
	} else {
		dataDispatcher.Register(log_define.LogCollector, collectWorker.DefaultWorker.GetQueue())
		return collectWorker, nil
	}
}
